﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GlassGrass.Unity.GuiFramework
	{
	/// <summary> Valid or invalid state and actual value pair. </summary>
	/// <typeparam name="T"></typeparam>
	public class Optional<T>
		{
		/// <summary> [get] If true then Value means valid value. </summary>
		public bool IsValidValue { get; }

		/// <summary> [get] Actual value. </summary>
		public T Value { get; }

		/// <summary> Create Optional instance which means invalid value. </summary>
		public Optional()
			{
			IsValidValue = false;
			Value = default(T);
			}

		/// <summary> Create Optional instance which means valid value. </summary>
		/// <param name="value"></param>
		public Optional(T value)
			{
			IsValidValue = true;
			Value = value;
			}

		/// <summary> Means invalid value. </summary>
		public static Optional<T> Invalid
			=> new Optional<T>();

		/// <summary> Implicit casting from actual value to Optional. </summary>
		/// <param name="value"></param>
		public static implicit operator Optional<T>(T value)
			=> new Optional<T>(value);
		}
	}
